﻿using System;
using System.Web;
using System.Web.SessionState;
using wojilu.Web.Code;

namespace wojilu.Web.Handler
{
    public class VerifyCodeHandler : IHttpHandler, IRequiresSessionState
    {
        private static readonly ILog logger = LogManager.GetLogger(typeof(VerifyCodeHandler));

        public Boolean IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            //防止网页后退--禁止缓存    
            context.Response.Expires = 0;
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.CacheControl = "no-cache";

            var t = context.Request.QueryString["t"].ToInt();
            if (t == 0)
            {
                t = 14;
            }
            var type = context.Request.QueryString["type"].ToInt();
            var len = context.Request.QueryString["len"].ToInt();
            if (len == 0)
            {
                len = 5;
            }
            VerifyCode image = new VerifyCode();
            image.EnglishOrNumChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            image.FontSize = t;
            image.DrawImage(type, len, 0);
        }

    }
}